package com.auth.manager.service.index.impl;

import com.auth.manager.pojo.sys.SysMenu;
import com.auth.manager.pojo.sys.SysRole;
import com.auth.manager.pojo.sys.UserInfo;
import com.auth.manager.service.index.IndexService;
import com.auth.manager.service.sys.SysMenuService;
import com.auth.manager.service.sys.SysRoleService;
import com.auth.manager.service.sys.UserInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @version 1.0.0
 * @Date: 2022/5/8 19:23
 * @Author ZhuYouBin
 * @Description
 */
@Service
public class IndexServiceImpl implements IndexService {

    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private SysRoleService sysRoleService;
    @Autowired
    private SysMenuService sysMenuService;

    @Override
    public Map<String, Long> findIndexCardData() {
        Map<String, Long> map = new HashMap<>();
        // 统计用户总数
        QueryWrapper<UserInfo> userWrapper = new QueryWrapper<>();
        userWrapper.eq("deleted", "01");
        long userCount = userInfoService.count(userWrapper);

        // 统计角色总数
        QueryWrapper<SysRole> roleWrapper = new QueryWrapper<>();
        roleWrapper.eq("deleted", "01");
        long roleCount = sysRoleService.count(roleWrapper);

        // 统计权限总数
        QueryWrapper<SysMenu> menuWrapper = new QueryWrapper<>();
        menuWrapper.eq("deleted", "01");
        long menuCount = sysMenuService.count(menuWrapper);

        map.put("userCount", userCount);
        map.put("roleCount", roleCount);
        map.put("menuCount", menuCount);
        return map;
    }
}
